package com.shaw.workrecord.config;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        LocalDateTime localDateTime = DateUtil.toLocalDateTime(new DateTime());
        this.setFieldValByName("createTime", localDateTime, metaObject);
        this.setFieldValByName("modifyTime", localDateTime, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        LocalDateTime localDateTime = DateUtil.toLocalDateTime(new DateTime());
        this.setFieldValByName("modifyTime", localDateTime, metaObject);
    }
}
